<template>
  <div class="top-view">
    <div class="button-div">
      <je-button
        v-for="item in topViewData.topButton"
        :key="item.key"
        style="margin-left: 10px"
        :class="`${topViewData.topSelectedKey == item.key ? 'btnSelected' : ''}`"
        type="text"
        size="small"
        @click="clickFirstButton(item.key)"
        >{{ item.text }}</je-button
      >
    </div>
    <div class="button-div bottom">
      <je-button
        v-for="item in eventInfoData"
        :key="item.onId"
        style="margin-left: 10px"
        type="text"
        :class="`${topViewData.bottomSelectedKey == item.onId ? 'btnSelected' : ''}`"
        size="small"
        @click="clickTwoButton(item)"
        >{{ item.text }}</je-button
      >
    </div>
  </div>
</template>

<script>
  import { defineComponent, reactive } from 'vue';
  import { Button } from '@jecloud/ui';
  export default defineComponent({
    name: 'TopView',
    components: {
      JeButton: Button,
    },
    props: {
      eventInfoData: {
        type: Object,
        default: () => {
          return {};
        },
      },
    },
    emits: ['buttonActive'],
    setup(props, { emit }) {
      const topViewData = reactive({
        topButton: [
          { text: '功能', key: 'func' },
          { text: '列', key: 'column' },
          { text: '字段', key: 'field' },
          { text: '按钮', key: 'button' },
          { text: 'Action列', key: 'actioncolumn' },
        ],
        bottomButton: props.eventInfoData,
        topSelectedKey: '',
        bottomSelectedKey: '',
      });

      //点击第一排按钮
      const clickFirstButton = (key) => {
        if (topViewData.topSelectedKey != key) {
          topViewData.bottomSelectedKey = '';
          topViewData.topSelectedKey = key;
          emit('buttonActive', { clickType: 'frist', type: key });
        }
      };

      //点击第二排按钮
      const clickTwoButton = (item) => {
        topViewData.bottomSelectedKey = item.onId;
        emit('buttonActive', {
          clickType: 'two',
          type: item.type,
          onId: item.onId,
          eventInfo: item.eventInfo,
          fieldType: item.fieldType,
        });
      };
      return { topViewData, clickFirstButton, clickTwoButton };
    },
  });
</script>

<style lang="less" scoped>
  .top-view {
    height: 100%;
    border: 1px solid #e6e6e6;
    .button-div {
      height: 40px;
      line-height: 40px;
      .ant-btn-text.btnSelected {
        background: rgba(0, 0, 0, 0.2) !important;
      }
      &.bottom {
        border-top: 1px solid #e6e6e6;
      }
    }
  }
</style>
<style lang="less"></style>
